﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.ComponentModel;
using System.Text;
using System.Collections.Generic;
using TA.Turbo.Design;


namespace TA.Turbo.Controls
{
	/// <summary>
	/// Base class for server-side events which are originated on the client side.
	/// </summary>
	public abstract class BaseServerEvent : ClientEvent
	{
		#region PUBLIC
		#region INIT
		/// <summary>
		/// Ctor.
		/// </summary>
		public BaseServerEvent()
			: base()
		{
			this.PostScenarioId = "";
		}
		#endregion
		#region EVENTS
		#endregion
		#region PROPS
		/// <summary>
		/// The ID of the post scenario to use when raising the event.
		/// </summary>
		[DefaultValue("")]
		[TypeConverter(typeof(ControlIdConverter<PostScenarioIdLister>))]
		[IDReferenceProperty]
		[NotifyParentProperty(true)]
		public string PostScenarioId
		{
			get
			{
				//if (string.IsNullOrEmpty(_postScenarioId))
				//{
				//  Init();
				//}
				return _postScenarioId;
			}
			set
			{
				_postScenarioId = value;
				_postScenario = null;
			}
		}
		/// <summary>
		/// The post scenario to use when raising the event.
		/// </summary>
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public PostScenario PostScenario
		{
			get
			{
				if (_postScenario == null)
				{
					if (!string.IsNullOrEmpty(PostScenarioId))
					{
						this._postScenario = this._c.FindControlGlobal(PostScenarioId) as PostScenario;
						if (this._postScenario == null)
							throw new InvalidOperationException(string.Format("The PostScenario with the Id '{0}' wasn't found.", this.PostScenarioId));
					}
				}
				return this._postScenario;
			}
			set
			{
				this._postScenarioId = value.UniqueID;
				this._postScenario = value;
			}
		}
		/// <summary>
		/// When implemented, gets true if any handlers are attached to the server side event delegate.
		/// </summary>
		[Browsable(false)]
		public abstract bool Active { get; }
		#endregion
		#region METHODS
		public void CopyFrom(BaseServerEvent source)
		{
			base.CopyFrom(source);

			this.PostScenario = source.PostScenario;
		}
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		#endregion
		#region VARS
		string _postScenarioId;
		PostScenario _postScenario;
		#endregion
		#region PROPS
		#endregion
		#region METHODS
		#region INIT
		#endregion
		#region DATA
		#endregion
		#region HANDLERS
		#endregion
		#endregion
		#endregion				
				

	}

}